package com.github.testdynabean;

import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;

/**
 *
 * @author www.javadb.com
 */
public class DynaBeanExample {

	private final String NR_OF_WHEELS = "numberOfWheels";

	private void runExample() {

		DynaClass dynaClass = new BasicDynaClass("Car", null,
				new DynaProperty[] { new DynaProperty(NR_OF_WHEELS, Integer.TYPE) });

		try {
			DynaBean car = dynaClass.newInstance();
			car.set(NR_OF_WHEELS, 4);

			System.out.println("Number of wheels: " + car.get(NR_OF_WHEELS));

			System.out.println("DynaBean is instance of DynaClass: " + car.getDynaClass().getName());

		} catch (IllegalAccessException | InstantiationException ex) {
			System.err.println(ex.getMessage());
		}
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String[] args) {
		DynaBeanExample ac = new DynaBeanExample();
		ac.runExample();
	}
}
